package org.jeecg.modules.exTenderFile.service.impl;

import org.jeecg.modules.exTenderFile.entity.ExZbwjConformanceReview;
import org.jeecg.modules.exTenderFile.entity.ExZbwjConformanceReviewBidDetail;
import org.jeecg.modules.exTenderFile.entity.ExZbwjConformanceReviewDetail;
import org.jeecg.modules.exTenderFile.mapper.ExZbwjConformanceReviewBidDetailMapper;
import org.jeecg.modules.exTenderFile.mapper.ExZbwjConformanceReviewDetailMapper;
import org.jeecg.modules.exTenderFile.mapper.ExZbwjConformanceReviewMapper;
import org.jeecg.modules.exTenderFile.service.IExZbwjConformanceReviewService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: ex_zbwj_conformance_review
 * @Author: jeecg-boot
 * @Date:   2024-11-07
 * @Version: V1.0
 */
@Service
public class ExZbwjConformanceReviewServiceImpl extends ServiceImpl<ExZbwjConformanceReviewMapper, ExZbwjConformanceReview> implements IExZbwjConformanceReviewService {

	@Autowired
	private ExZbwjConformanceReviewMapper exZbwjConformanceReviewMapper;
	@Autowired
	private ExZbwjConformanceReviewBidDetailMapper exZbwjConformanceReviewBidDetailMapper;
	@Autowired
	private ExZbwjConformanceReviewDetailMapper exZbwjConformanceReviewDetailMapper;
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void saveMain(ExZbwjConformanceReview exZbwjConformanceReview, List<ExZbwjConformanceReviewBidDetail> exZbwjConformanceReviewBidDetailList,List<ExZbwjConformanceReviewDetail> exZbwjConformanceReviewDetailList) {
		exZbwjConformanceReviewMapper.insert(exZbwjConformanceReview);
		if(exZbwjConformanceReviewBidDetailList!=null && exZbwjConformanceReviewBidDetailList.size()>0) {
			for(ExZbwjConformanceReviewBidDetail entity:exZbwjConformanceReviewBidDetailList) {
				//外键设置
				entity.setConformanceReviewId(exZbwjConformanceReview.getId());
				exZbwjConformanceReviewBidDetailMapper.insert(entity);
			}
		}
		if(exZbwjConformanceReviewDetailList!=null && exZbwjConformanceReviewDetailList.size()>0) {
			for(ExZbwjConformanceReviewDetail entity:exZbwjConformanceReviewDetailList) {
				//外键设置
				entity.setConformanceReviewId(exZbwjConformanceReview.getId());
				exZbwjConformanceReviewDetailMapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateMain(ExZbwjConformanceReview exZbwjConformanceReview,List<ExZbwjConformanceReviewBidDetail> exZbwjConformanceReviewBidDetailList,List<ExZbwjConformanceReviewDetail> exZbwjConformanceReviewDetailList) {
		exZbwjConformanceReviewMapper.updateById(exZbwjConformanceReview);
		
		//1.先删除子表数据
		exZbwjConformanceReviewBidDetailMapper.deleteByMainId(exZbwjConformanceReview.getId());
		exZbwjConformanceReviewDetailMapper.deleteByMainId(exZbwjConformanceReview.getId());
		
		//2.子表数据重新插入
		if(exZbwjConformanceReviewBidDetailList!=null && exZbwjConformanceReviewBidDetailList.size()>0) {
			for(ExZbwjConformanceReviewBidDetail entity:exZbwjConformanceReviewBidDetailList) {
				//外键设置
				entity.setConformanceReviewId(exZbwjConformanceReview.getId());
				exZbwjConformanceReviewBidDetailMapper.insert(entity);
			}
		}
		if(exZbwjConformanceReviewDetailList!=null && exZbwjConformanceReviewDetailList.size()>0) {
			for(ExZbwjConformanceReviewDetail entity:exZbwjConformanceReviewDetailList) {
				//外键设置
				entity.setConformanceReviewId(exZbwjConformanceReview.getId());
				exZbwjConformanceReviewDetailMapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		exZbwjConformanceReviewBidDetailMapper.deleteByMainId(id);
		exZbwjConformanceReviewDetailMapper.deleteByMainId(id);
		exZbwjConformanceReviewMapper.deleteById(id);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			exZbwjConformanceReviewBidDetailMapper.deleteByMainId(id.toString());
			exZbwjConformanceReviewDetailMapper.deleteByMainId(id.toString());
			exZbwjConformanceReviewMapper.deleteById(id);
		}
	}
	
}
